package com.itljm.cxrMarket.security;

import com.itljm.cxrMarket.entity.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

/**
 * 权限判断
 * @author ljm
 * @date 2024/11/4 17:32
 */
@Component("securityAuthority")
public class SecurityAuthority {
    public boolean hasAuthority(String authority){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        return loginUser.getPermissions().contains(authority);
    }

}
